<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="avicit.platform6.commons.utils.ViewUtil"%>
<%@ page import="avicit.platform6.commons.utils.ComUtil"%>
<%@ taglib prefix="sec" uri="/WEB-INF/tags/shiro.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="avicit.platform6.core.locale.PlatformLocalesJSTL"%>
<%@page import="java.util.Locale"%>
<%@page import="avicit.platform6.api.session.SessionHelper"%>
<%@page import="avicit.platform6.api.sysshirolog.impl.AfterLoginSessionProcess"%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <base href="<%=ViewUtil.getRequestPath(request)%>">
        <%
Object lang=session.getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
String languageCode="zh_CN";
if(lang!=null){
	languageCode=lang.toString();
}
	Locale locale =SessionHelper.getLocaleByUser(request);
%>
    <jsp:include page="/avicit/platform6/component/common/EasyUIJsInclude.jsp"></jsp:include>
    <jsp:include page="/avicit/im/common/ImUIJSCSSInclude.jsp"></jsp:include>
    <script src="static/js/platform/component/common/exportData.js" type="text/javascript"></script>
    <script type="text/javascript" src="avicit/im/lantop/basic/reportmanager/locale/language_<%=languageCode%>.js"></script>
    <script type="text/javascript" src="avicit/im/lantop/basic/reportmanager/js/LantopFineReport.js"></script>

    <title>报表管理</title>
    <script type="text/javascript">
        var baseHref = '<%=ViewUtil.getRequestPath(request)%>';
        //  接收后台传递的参数
        var sysId = '${sysId}';
        var orgId = '${orgId}';
        var dialogId = '${dialogId}';
        var tableNameIds = '${tableNameIds}';
        var templateId = '${templateId}';
        var lantopFineReport;
        var type = "root";
        var iframeHeight =  document.documentElement.clientHeight;
        $(function(){
            if (orgId != 'ORG_ROOT') {
                $('#rootTree').css('height', iframeHeight / 2 - 13);
                $('#childTree').css('height', iframeHeight / 2 - 13);
            } else {
                $('#rootTree').css('height', iframeHeight - 27);
            }
            lantopFineReport = new LantopFineReport("<%=ViewUtil.getRequestPath(request)%>", {
                op : "write",
                __showtoolbar__ : "false"
            }, "reportView", false);
            $("#reportTree").tree({
                checkbox : false, 			// 是否带复选框
                lines : true, 				// 线条
                method : 'post',
                url : "platform/im/lantop/basic/ReportManagerController/gettree/-1/null?sysId="+sysId,
                dataType : "json", /* 数据格式 */
                formatter:function(node){
                    if(node._parentId=="-1"){
                        //_self._rootId=node.id;
                    }
                    if(node.attributes && node.attributes.s){
                        return '<a style="color:#fff;font-weight:normal;background:#3399ff;padding:0 4px;">' + node.text + '</a>';
                    }else{
                        return node.text;
                    }
                },

                loadFilter : function(data) {
                    // 过滤后台返回的数据，处理不同JSON结构
                    if (data.data) {
                        return data.data;
                    } else {
                        return data;
                    }
                },

                onClick : function(node) {
                    $("#reportTree").tree('select', node.target);
                    // 模板， 加载其所对应的模板
                    if (node.attributes.reportType == '1') {
                        lantopFineReport.submit({
                            SQL : "SELECT ' ' FROM DUAL",
                            reportlet : node.attributes.cptFileName
                        });
                    }
                    type = "nRoot";
                },
                formatter : function(node) {
                    return '<span title="' + node.text + '">' + node.text + '</span>';
                }
            });


            //根组织树初始化
            $("#reportTreeRoot").tree({
                checkbox : false, 			// 是否带复选框
                lines : true, 				// 线条
                method : 'post',
                url : "platform/im/lantop/basic/ReportManagerController/gettree/-1/root?sysId="+sysId,
                dataType : "json", /* 数据格式 */
                formatter:function(node){
                    if(node._parentId=="-1"){
                        //_self._rootId=node.id;
                    }
                    if(node.attributes && node.attributes.s){
                        return '<a style="color:#fff;font-weight:normal;background:#3399ff;padding:0 4px;">' + node.text + '</a>';
                    }else{
                        return node.text;
                    }
                },

                loadFilter : function(data) {
                    // 过滤后台返回的数据，处理不同JSON结构
                    if (data.data) {
                        return data.data;
                    } else {
                        return data;
                    }
                },

                onClick : function(node) {
                    $("#reportTreeRoot").tree('select', node.target);
                    // 模板， 加载其所对应的模板
                    if (node.attributes.reportType == '1') {
                        lantopFineReport.submit({
                            SQL : "SELECT ' ' FROM DUAL",
                            reportlet : node.attributes.cptFileName
                        });
                    }
                    type = "root";
                },
                formatter : function(node) {
                    return '<span title="' + node.text + '">' + node.text + '</span>';
                }

            });

        });

        // 确定按钮
        function save(){
            // 需要判断是否是已经配置过的，如果是则直接打印, 否则则需要弹出配置窗口
            var node;
            if(type == "root"){
                node = $("#reportTreeRoot").tree('getSelected');
            }else{
                node = $("#reportTree").tree('getSelected');
            }
            var templateId = node.id;
            if(node == null || node.length == 0 || node.attributes.reportType == '0'){
                //'提示', "请选择一个模板！"
                $.messager.alert("<%=PlatformLocalesJSTL.getBundleValue("lantop.remind","i18n.lantop",locale)%>"," <%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.printselectreport.choosetemplate","i18n.lantop",locale)%>", 'warning');
                return ;
            }
            var outPutFields;
            if(node.attributes.hasField){
                outPutFields = node.attributes.fields;  // 取出应输出字段
            } else {
                outPutFields = $(
                    $(window.frames["reportView"].document).find("#r-0-0").find(
                        "td")[0]).text();
                if ("" == outPutFields) {//无输出字段
                    $.messager.alert(commonLang.tip.alert, commonLang.tip.templateNoFiled, 'warning');
                    return;
                }
            }

            //var resultDataSource = node.attributes.resultDataSource;


            outPutFields = encodeURI(encodeURI(outPutFields));


            // 总是打开数据源配置界面,
            //if(undefined != resultDataSource ){
            // 未配置过数据源, 打开配置界面
            var dialogId = "printfSelectConfigDialog";
            //'报表配置'
            var config = new CommonDialog(dialogId, "900", "450",
                'platform/im/lantop/basic/ReportManagerController/printfreportconfig?dialogId=' + dialogId + "&outPutFields=" + outPutFields + "&templateId=" +templateId + "&tableNameIds=" + tableNameIds +"&sysId=" + sysId, commonLang.tip.templateConfig, false, true, false,false,true);
            config.show();
            //parent.$(".panel-tool-max panel-tool-restore").css({display : 'none'});


            //}

        }

        // 取消按钮
        function cancel(){
            // 需要刷新父页面
            parent.reLoadTree();
            parent.reLoadTreeRoot();
            parent.$("#" + dialogId).dialog('close');

        }


    </script>
<body class="easyui-layout" data-options="fit:true">

<div data-options="region:'north',title:'North Title',split:false, noheader:true" style="height: 30px; overflow: hidden;" class="datagrid-toolbar"">


<%--确定 --%>
<a class="easyui-linkbutton" plain="true" iconCls="icon-im-ok" onclick="save();" href="javascript:void(0);"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.printselectreport.confirm","i18n.lantop",locale)%></a>
<%--取消 --%>
<a class="easyui-linkbutton" plain="true" iconCls="icon-im-cancel" onclick="cancel();" href="javascript:void(0);"><%=PlatformLocalesJSTL.getBundleValue("lantop.basicdatamanager.reportmanager.printselectreport.cancle","i18n.lantop",locale)%></a>


</div>

<div data-options="region:'center',title:'center title',split:false, noheader:true">
    <div id="cc" class="easyui-layout" style="height: 100%; margin-left: 20px;">
        <div id="rootTree" style="overflow: auto;">
            <ul id="reportTreeRoot"></ul>
        </div>
        <c:if test="${orgId != 'ORG_ROOT'}">
            <div id="childTree" style="overflow: auto;">
                <ul id="reportTree"></ul>
            </div>
        </c:if>
    </div>
</div>
<div style="display: none;">
    <iframe id="reportView" name="reportView" width="100%" height="100%" frameborder="0"></iframe>
</div>
</body>
</html>